%option noyywrap
%{

#include "eetc.h"
#include "y.tab.h"

%}

%s C_COMMENT
%s EET_STRUCT

	int sc;

D			[0-9]
L			[a-zA-Z_]
H			[a-fA-F0-9]
IS			(u|U|l|L)*

%%

<C_COMMENT>{
	"@EET{" 	{ sc = EET_STRUCT; }
	"@}"		{ sc = INITIAL; }
}
<EET_STRUCT>{
	"char"		{ return CHAR; }
	"short"		{ return SHORT; }
	"int"		{ return INT; }
	"long"		{ return LONG; }
	"float"		{ return FLOAT; }
	"double"	{ return DOUBLE; }
	"struct"	{ return STRUCT; }
	"typedef"	{ return TYPEDEF; }
	{L}({L}|{D})* 	{
				yylval.s = strdup(yytext);
				return check_type(yylval.s);
			}

	0[xX]{H}+{IS}? 	{
				yylval.i = atoi(yytext);
				return CONSTANT;
			}
	0{D}+{IS}?	{
				yylval.i = atoi(yytext);
				return CONSTANT;
			}
	{D}+{IS}?	{
				yylval.i = atoi(yytext);
				return CONSTANT;
			}
	"*"		{ return '*'; }
	"{"		{ return '{'; }
	"}"		{ return '}'; }
	";"		{ return ';'; }
}
\n                      /* ignore end of line */
^#.*			/* ignore preprocessor */
[ \t]+                  /* ignore whitespace */
"/*" 			{ sc = INITIAL; BEGIN C_COMMENT; }
"*/"			{ BEGIN sc; }
.			/* everything else ignored */

%%

int check_type(const char *name)
{
	/* get the identifier if it exists, if not create a new one */
	return IDENTIFIER;
}
